import {
  reqUserInfo,
} from '../../api/index'
Page({
  data: {
    nickname: '',
    headimgurl: ''
  },
  onLoad(options) {
    //先看本地存储是有有token
    let token = wx.getStorageSync('TOKEN');
    if (token) {
      this.getUserInfo();
    }
  },
  //登录按钮的回调
  login() {
    //跳转到登录
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  //获取用户信息
  async getUserInfo() {
    let result = await reqUserInfo();
    if (result.code == 200) {
      this.setData({
        nickname: result.data.nickname,
        headimgurl: result.data.headimgurl
      })
    }
  },
  goEdit(){
    wx.navigateTo({
      url: '/pages/edit/edit',
    })
  }
})